package org.budo.dubbo.http.client.java.exception;

import lombok.Getter;
import lombok.Setter;

/**
 * 请求失败信息
 * 
 * @author lmw
 */
@Getter
@Setter
public class ApiErrorException extends RuntimeException {
    private static final long serialVersionUID = -6043220378283972245L;

    private Integer status;

    private String error;

    private String errorDescription;

    public ApiErrorException() {}

    public ApiErrorException(Integer status, String error, String errorDescription) {
        this.setStatus(status);
        this.setError(error);
        this.setErrorDescription(errorDescription);
    }

    public ApiErrorException(String message) {
        super(message);
    }

    public ApiErrorException(Throwable cause) {
        super(cause);
    }

    public String getMessage() {
        if (null != this.getCause()) {
            return this.getCause().toString();
        } else if (null != this.getStatus()) {
            return "status=" + this.getStatus() + ", error=" + this.getError() + ", errorDescription=" + this.getErrorDescription();
        } else {
            return super.getMessage();
        }
    }

    public synchronized Throwable fillInStackTrace() {
        return this;
    }
}